const {defineConfig} = require('@vue/cli-service')
const os = require('os');
const machineId = require('node-machine-id');

function getNetworkIp() {
    let needHost = '';
    try {
        const network = os.networkInterfaces();
        for (const dev in network) {
            const iface = network[dev];
            for (let i = 0; i < iface.length; i++) {
                const alias = iface[i];
                if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                    needHost = alias.address;
                }
            }
        }
    } catch (e) {
        needHost = 'localhost';
    }
    return needHost;
}

const myHost = getNetworkIp();
const myName = os.hostname();
process.env.VUE_APP_HOST = myHost; // IP 地址
process.env.VUE_APP_NAME = myName; // 主机名

// 获取设备 ID
const id = machineId.machineIdSync({original: true});
process.env.VUE_APP_MACHINEID = id; // 设备 ID

// 导出配置
/*
module.exports = defineConfig({
    transpileDependencies: true,
    devServer: {
        client: {
            progress: true,
            overlay: false,
        },
        open: true,
        host: '0.0.0.0',
        hot: true,
        port: '8080',
        proxy: {
            '/api': {
                /!*target: 'http://192.168.3.155:9999'*!//!*古*!/
                target: 'http://192.168.3.211:9999',/!*游*!/
                /!*target: process.env.VUE_APP_BASE_HOST,*!//!*游*!/
                changeOrigin: true,
                pathRewrite: {
                    '^/api': ''
                }
            },
            '/yb-api': {
                target: 'http://10.114.177.55:8080',
                changeOrigin: true,
                pathRewrite: {'^/yb-api': ''},
                headers: {
                    'Origin': 'http://localhost:8080',
                    'Referer': 'http://localhost:8080'
                }
            }
        }
    },
})*/
